/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.yunhoo.report.bean;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;

/**
 *
 * @author Administrator
 */
public class ReportHeaderGetter {

    public Object[] getReportHeader(String filePath) {
        Object[] hd = null;
        try {
            ServletContext scontext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
            Properties props = new Properties();
            InputStream in = new FileInputStream(scontext.getRealPath(filePath));
            props.load(in);
            int i = 0;
            String level = null;
            List templi = new ArrayList();
            while (level != null) {
                level = props.getProperty("level" + i++);
                if (level != null) {
                    level.replaceAll(" +", "");
                    templi.add(level);
                }
                System.out.println("level " + i + " : " + level);
            }
            hd = templi.toArray();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return hd;
    }

    public List<String> getReportQueryParam(String filePath) {
        List templi = new ArrayList();
        try {
            ServletContext scontext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
            Properties props = new Properties();
            InputStream in = new FileInputStream(scontext.getRealPath(filePath));
            props.load(in);
            int i = 0;
            String col = "";
            while (col != null) {
                col = props.getProperty("col" + i++);
                if (col != null) {
                    String code = col.split(" +")[0];
                    templi.add(code.trim());
                    System.out.println("col" + i + " = " + col);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return templi;
    }
}
